import 'package:flutter/material.dart';

import '../../config/public_color.dart';
import '../../foundation/style/bold_text_style.dart';
import '../../foundation/style/medium_text_style.dart';
import '../../foundation/style/normal_text_style.dart';
import '../container/separated_column.dart';
import '../text/require_text.dart';

/// FileName vertical_item
///
/// @Author lax
/// @Date 2024/5/24
///
/// @Description

class VerticalItem extends StatelessWidget {
  static TextStyle? defaultTitleStyle;

  static TextStyle? defaultValueStyle;

  static TextStyle? defaultUnableTitleStyle;

  static TextStyle? defaultUnableValueStyle;

  static TextStyle? defaultHintTextStyle;

  static EdgeInsets? defaultPadding =
      const EdgeInsets.symmetric(horizontal: 16, vertical: 16);

  final String? title;
  final String? value;
  final String? hintText;

  final bool enable;
  final bool required;

  late final EdgeInsets padding;

  late final TextStyle? titleStyle;
  late final TextStyle? valueStyle;
  late final TextStyle? unableTitleStyle;
  late final TextStyle? unableValueStyle;
  late final TextStyle? hintTextStyle;

  final Widget? topWidget;
  final Widget? bottomWidget;
  final Widget? titleWidget;
  final Widget? valueWidget;
  final Widget? separator;

  final MainAxisAlignment mainAxisAlignment;
  final CrossAxisAlignment crossAxisAlignment;

  VerticalItem({
    super.key,
    this.title,
    this.value,
    this.hintText,
    this.enable = true,
    this.required = false,
    EdgeInsets? padding,
    TextStyle? titleStyle,
    TextStyle? valueStyle,
    TextStyle? unableTitleStyle,
    TextStyle? unableValueStyle,
    TextStyle? hintTextStyle,
    this.topWidget,
    this.bottomWidget,
    this.titleWidget,
    this.valueWidget,
    this.separator = const SizedBox(height: 12),
    this.mainAxisAlignment = MainAxisAlignment.start,
    this.crossAxisAlignment = CrossAxisAlignment.start,
  }) {
    this.titleStyle = titleStyle ?? defaultTitleStyle ?? BoldTextStyle();
    this.valueStyle = valueStyle ?? defaultValueStyle ?? NormalTextStyle();
    this.unableTitleStyle =
        unableTitleStyle ?? defaultUnableTitleStyle ?? MediumTextStyle();
    this.unableValueStyle =
        unableValueStyle ?? defaultUnableValueStyle ?? NormalTextStyle();
    this.hintTextStyle = hintTextStyle ??
        defaultHintTextStyle ??
        TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.normal,
            color: PublicColor.hintText);
    this.padding = padding ?? defaultPadding ?? EdgeInsets.zero;
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> children = [];
    if (titleWidget != null || title != null) {
      children.add(
        titleWidget ??
            RequireText(
              text: title,
              style: enable ? titleStyle : unableTitleStyle,
              required: required,
            ),
      );
    }
    if (topWidget != null) {
      children.add(topWidget!);
    }
    if (valueWidget != null || value != null || (enable && hintText != null)) {
      children.add(valueWidget ??
          Text(
            enable ? (value ?? hintText ?? '') : (value ?? ''),
            style: enable
                ? (value == null ? hintTextStyle : valueStyle)
                : unableValueStyle,
          ));
    }
    if (bottomWidget != null) {
      children.add(bottomWidget!);
    }
    return SeparatedColumn(
      padding: padding,
      alignment: Alignment.centerLeft,
      mainAxisAlignment: mainAxisAlignment,
      crossAxisAlignment: crossAxisAlignment,
      separator: separator,
      children: children,
    );
  }
}
